package com.wbp.cms.core.user.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.wbp.cms.client.customer.domain.CustomerDO;
import com.wbp.cms.client.customer.query.CustomerQuery;
import com.wbp.cms.client.user.domain.UserDO;
import com.wbp.cms.client.user.query.UserQuery;
import com.wbp.cms.core.dao.BaseDao;


/**
 * @Description:
 * @Department:
 * @author andy.lhc
 * @date 2016年3月6日 下午11:10:34
 */
@Repository("userDAO")
public class UserDAO extends BaseDao {

  public Long insert(UserDO userDO) {
    super.insert("UserMapper.insert", userDO);
    return userDO.getId();
  }

  public int update(UserDO userDO) {
    return super.update("UserMapper.update", userDO);
  }

  public List<UserDO> query(UserQuery userQuery) {
    return super.selectList("UserMapper.query", userQuery);
  }
  
  public  UserDO  queryUserByUserName(String userName) {
    UserQuery  query =new UserQuery();
    query.setUserName(userName);
    List<UserDO>  list = query(query) ;
    if(list ==null || list.isEmpty())
      return null ;
    return  list.get(0) ;
  }

  public Integer queryCount(UserQuery userQuery) {
    Object obj = super.selectOneObject("UserMapper.queryCount", userQuery);
    return obj == null ? 0 : (Integer) obj;

  }

  public UserDO load(Long id) {
    Object obj = super.selectOneObject("UserMapper.load", id);
    return obj == null ? null : (UserDO) obj;
  }

  public List<UserDO> queryUserByOrg(UserQuery userQuery) {
    return super.selectList("UserMapper.queryUserByOrg", userQuery);
  }

  public Integer queryUserByOrgCount(UserQuery userQuery) {
    Object obj = super.selectOneObject("UserMapper.queryUserByOrgCount", userQuery);
    return obj == null ? 0 : (Integer) obj;
  }

}
